Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a little something that was in the back of my head for some time – but it's only for after the new animation API is in.
Context
I've found myself copy & pasting over code to handle non-linear interpolation (aka easing) for animation over and over again. So I had this idea it could be cool if mechanic provided a simple way to use the most common easing functions without having to re-code them yourself.
What this does
This adds a
@mechanic-design/transition
package that exposes a generic interpolation helper to the user. It also comes with pre-built versions of the most commonly used easing functions for quick access. But users’ can also bring their own easing function if they wanted to.The transition function is setup as a curried function, to encourage a clean usage based on animation lifecycle events—the transition should be set up when setting up your design function and then in the draw loop you only pull values from it.
Examples
The most basic example, animating a rectangle’s position:
Using a custom easing function:
The transition helper only works with numerical values. You could however still use it to interpolate non numerical values (like color), by using the transition helper to generate the easing curve for you and then passing a normalized transition value to a specific interpolation function. The example shows this